package com.app.datasource;

import javax.sql.DataSource;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author ch
 * @date 2022/12/14 10:45
 */
public abstract class AbstractDatabaseFactory {
    public static Map<String, DatabaseFactoryBean> databaseMap = new ConcurrentHashMap<>();

    public DatabaseFactoryBean createDatabaseFactoryBean(DatasourceInfo info) {
        DataSource dataSource = init(info);
        DatabaseFactoryBean databaseFactoryBean = new DatabaseFactoryBean();
        databaseFactoryBean.setId(info.getId());
        databaseFactoryBean.setName(info.getName());
        databaseFactoryBean.setUrl(info.getUrl());
        databaseFactoryBean.setDataSource(dataSource);
        return databaseFactoryBean;
    }

    public abstract DataSource init(DatasourceInfo info);
}
